import 'package:flutter/cupertino.dart';

import '../../../data/models/bt_user_info.dart';
import '../repository/bt_profile_repository.dart';

class BtModifyUserInfoModel extends ChangeNotifier {
  String _nickname = '';

  String get nickname => _nickname;

  String _birthday = '';

  String get birthday => _birthday;

  String _avatarUrl = '';

  String get avatarUrl => _avatarUrl;

  late final BtProfileRepository repository;

  BtModifyUserInfoModel(BtUserInfo userInfo) {
    repository = BtProfileRepository();

    _nickname = userInfo.nickname;
    _birthday = userInfo.birthday ?? '';
    _avatarUrl = userInfo.avatarUrl;
  }

  Future<void> loadUserInfo() async {
    //await Future.delayed(const Duration(seconds: 1));
  }

  void setAvatarUrl(String avatarUrl) {
    _avatarUrl = avatarUrl;
    notifyListeners();
  }

  void setNickname(String nickname) {
    _nickname = nickname;
  }

  void setBirthday(String birthday) {
    _birthday = birthday;
  }

  void updateUserInfo(Function(bool success, String msg) onResult) {
    repository.saveUserInfo(_nickname, _birthday, onResult);
  }
}
